package org.martyn.danbooru.utils;

import java.util.List;

import org.apache.http.NameValuePair;

public class URLUtils
{
	private static final String PARAMETER_SEPARATOR = "&";
	private static final String NAME_VALUE_SEPARATOR = "=";

	public static String buildQuery(
			final List<? extends NameValuePair> parameters)
	{
		final StringBuilder result = new StringBuilder();

		for (NameValuePair parameter : parameters)
		{
			final String name = parameter.getName();
			final String value = parameter.getValue();

			if (result.length() > 0)
			{
				result.append(PARAMETER_SEPARATOR);
			}

			result.append(name);
			result.append(NAME_VALUE_SEPARATOR);
			result.append(value);
		}

		return result.toString();
	}

	/*
	 * public static String format (final List <? extends NameValuePair>
	 * parameters, final String encoding) { final StringBuilder result = new
	 * StringBuilder();
	 * 
	 * for (final NameValuePair parameter : parameters) { final String
	 * encodedName = encode(parameter.getName(), encoding); final String value =
	 * parameter.getValue(); final String encodedValue = value != null ?
	 * encode(value, encoding) : "";
	 * 
	 * if (result.length() > 0) { result.append(PARAMETER_SEPARATOR); }
	 * 
	 * result.append(encodedName); result.append(NAME_VALUE_SEPARATOR);
	 * result.append(encodedValue); } return result.toString(); }
	 * 
	 * private static String encode (final String content, final String
	 * encoding) { try { return URLEncoder.encode(content, encoding != null ?
	 * encoding : HTTP.DEFAULT_CONTENT_CHARSET); } catch
	 * (UnsupportedEncodingException problem) { throw new
	 * IllegalArgumentException(problem); } }
	 */

}
